<%@ page contentType="text/html;charset=UTF-8"%>
<%@include file="../../common/sessionValidate.jsp" %>
<%@ page import="com.common.utils.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html lang="UTF-8">
  <head>
    <title>T_data_dic信息维护</title>
    <%@ include file="../../common/meta.jsp"%>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="X-UA-Compatible" content="IE=9">
	<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <link rel="stylesheet" href="<%=basePath%>css/my-bootstrap.css" media="screen"  id="tuserskin">
    <link rel="stylesheet" href="<%=basePath%>js/toastr/toastr.css">
    <link rel="stylesheet" href="<%=basePath%>css/font-awesome.min.css">

    <link href="<%=basePath%>css/switch/bootstrap3/highlight.css" rel="stylesheet">
    <link href="<%=basePath%>css/switch/bootstrap3/bootstrap-switch.css" rel="stylesheet">
    <link href="<%=basePath%>css/switch/bootstrap3/main.css" rel="stylesheet">

  </head>
  <style>
	hr {
	    //margin-top:1px;
	    border-bottom: 1px solid #1BBC9B;
	}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.navbar-brand {
height: 40px;
padding-top: 10px;
}
.navbar {
min-height: 40px;
}


.navbar-toggle {
margin-top: 4px;
margin-bottom: 4px;
}
  </style>
  <body>
  <div class="panel panel-primary" id="cxDiv">
	<div class="panel-heading  " >
		<i class='icon-cogs'></i>&nbsp;系统参数设置
	</div>
	<div class="panel-body" id="shDiv" class="panel-collapse collapse in">
		<nav class="navbar navbar-default" role="navigation">
		   <div>
		      <ul class="nav navbar-nav">
		         <li class=""><a href="toT_systemParamFactory">系统安全参数设置(开关)</a></li>
		         <li class=""><a href="toT_systemParamFactory2">产品参数设置</a></li>
		         <li class=""><a href="toT_systemParamFactory3">系统参数设置</a></li>
		         <li class="active"><a href="#">金融机构参数设置</a></li>
		         <li class=""><a href="toT_systemParamcoreList">核心企业参数设置</a></li>
		      </ul>
		   </div>
		</nav>
    </div>


     <div class="item_box box10">
	   <div class="item_box_wp">
		<div class="voice_2">
			<ul>
				<li class="li1" id="li1">
					<div class="fold" style="display:none;">

						<span class="txt">系统安全参数设置</span>
					</div>
					<div class="unfold" style="display:block">
						<dl>

							<dd>
								<b>系统安全参数设置</b>
							</dd>
							<dd>
							<hr>[1]、系统熔断(熔断后不能登录)
							<br>
								<div id="xtrdid">

								</div>
                            <hr>[2]、金融机构开关<br>
								<div id="jrjgid">
								</div>
							<hr>[3]、核心企业开关<br>
								<div id="hxqyid">
								</div>

							</dd>
						</dl>
					</div>
				</li>
			</ul>

		  </div>
	     </div>
        </div>

	  </div>
  </div>
  </body>
</html>

    <script src="<%=basePath%>js/switch/jquery.min.js"></script>
    <script src="<%=basePath%>js/switch/bootstrap.min.js"></script>
    <script src="<%=basePath%>js/switch/highlight.js"></script>
    <script src="<%=basePath%>js/switch/bootstrap-switch.js"></script>
    <script src="<%=basePath%>js/switch/main.js"></script>

    <script type="text/javascript" src="<%= basePath %>js/jquery.cookie.js"></script>
	<script src="<%=basePath%>js/toastr/toastr.js"></script>
	<script src="<%=basePath%>js/bootbox.js"></script>
	<script src="<%=basePath%>js/my-jquery-curd.js"></script>

<script type="text/javascript">

$().ready(function(){
	//1、初始化数据显示
	Search1(0);
	//Search2(0);
	//Search3(0);

}) //end funciton read;

//根据查询条件，查询列表数据并显示
function Search1(startIndex){
	var pageSize = 1000 ;//document.getElementById("pageSize").value;
	var condition = ""; //$("#form1").serialize();
	var url = "<%=basePath%>t_data_dic/getAllT_data_dic?startIndex="+startIndex+"&data_group=SYSTEM_RD&pageSize="+pageSize+"&"+condition+"&time="+Math.random();
	//alert(url);
	$.getJSON(url, function (data){
		$("#xtrdid").html("");
		var str='';
		var sdata_name;

		//1、表格行内容输出
	    $.each(data.items, function(i,item){
	    	if(item.data_name=="true"){
	    		sdata_name=true;
	    	}else{
	    		sdata_name=false;
	    	}
			str+=' 系统当前熔断状态:<input type="checkbox" checked id="xtrdSwitch" name="xtrdSwitch" data-on-text="已熔断" data-off-text="未熔断" data-on-color="danger" data-off-color="success" />';
			str+=' &nbsp;&nbsp;&nbsp;&nbsp;<button type="button" onclick="javascript:turnOffOrOn(\'true\',\''+item.data_no+'\')" class="btn btn-sm btn-primary" name="editSaveButton" id="editSaveButton">开启熔断</button>';
			str+=' <button type="button"  onclick="javascript:turnOffOrOn(\'false\',\''+item.data_no+'\')" class="btn btn-sm btn-primary" name="editSaveButton" id="editSaveButton">关闭熔断</button>';
			str+=' (当前数据库值：'+sdata_name+')说明：熔断=true; 正常=false';
	    });//end each data;
	    $("#xtrdid").html(str);
	    //$('[type="checkbox"]').bootstrapSwitch(); //没有这句，不会css显示为开关，只是一个checkbox；
	    $('#xtrdSwitch').bootstrapSwitch(); //没有这句，不会css显示为开关，只是一个checkbox；
	    //alert("zc?="+sdata_name);
	    if(sdata_name==false){
			//alert("------系统正常，进行初始化");
	    	$('#xtrdSwitch').bootstrapSwitch('toggleState');
	    	$('#xtrdSwitch').bootstrapSwitch('state', false);
	    	$('#xtrdSwitch').bootstrapSwitch('readonly', true);
	    	//alert("------系统正常，初始化为 false");
		}else{
			//alert("------系统熔断，进行初始化");
			$("#xtrdSwitch").bootstrapSwitch('toggleState');
	    	$('#xtrdSwitch').bootstrapSwitch('state', true);
	    	$('#xtrdSwitch').bootstrapSwitch('readonly', true);
	    	//alert("------系统熔断，初始化为  true");
		}

	    Search2(0);

    })//end getJSON;
}

//根据查询条件，查询列表数据并显示
function Search2(startIndex){
	var pageSize = 1000 ;//document.getElementById("pageSize").value;
	var condition = ""; //$("#form1").serialize();
	var url = "<%=basePath%>t_data_dic/getAllT_data_dic?startIndex="+startIndex+"&data_group=BANK_INTERFACE_SWITCH&pageSize="+pageSize+"&"+condition+"&time="+Math.random();
	//alert(url);
	$.getJSON(url, function (data){
		$("#jrjgid").html("");

		//1、表格行内容输出
	    $.each(data.items, function(i,item){
	    	var str2='';
	    	var jrjgname = "jrjgSwitch"+item.data_no;
	    	//alert("------jrjgname="+jrjgname);
			str2+= item.data_type_name+'： <input type="checkbox" checked id="'+jrjgname+'" name="'+jrjgname+'" data-on-text="已开启" data-off-text="已关闭" data-on-color="danger" data-off-color="success" />';
			str2+=' &nbsp;&nbsp;&nbsp;&nbsp;<button type="button"  onclick="javascript:turnOffOrOn(\'true\',\''+item.data_no+'\')" class="btn btn-sm btn-primary" name="editSaveButton" id="editSaveButton">开启</button>';
			str2+=' <button type="button"  onclick="javascript:turnOffOrOn(\'false\',\''+item.data_no+'\')" class="btn btn-sm btn-primary" name="editSaveButton" id="editSaveButton">关闭</button>';
			str2+=' (当前数据库值：'+item.data_name+')说明：已开启=true; 已关闭=false;<br>';
			$("#jrjgid").append(str2);
			$('[type="checkbox"]').bootstrapSwitch(); //没有这句，不会css显示为开关，只是一个checkbox；
			if(item.data_name=="false"){
		    	$('#'+jrjgname).bootstrapSwitch('toggleState');
		    	$('#'+jrjgname).bootstrapSwitch('state', false);
		    	$('#'+jrjgname).bootstrapSwitch('readonly', true);
			}else{
				$('#'+jrjgname).bootstrapSwitch('toggleState');
				$('#'+jrjgname).bootstrapSwitch('state', true);
				$('#'+jrjgname).bootstrapSwitch('readonly', true);
			}
		});//end each data;

	    Search3(0);
    })//end getJSON;
}

//根据查询条件，查询列表数据并显示
function Search3(startIndex){
	var pageSize = 1000 ;//document.getElementById("pageSize").value;
	var condition = ""; //$("#form1").serialize();
	var url = "<%=basePath%>t_data_dic/getAllT_data_dic?startIndex="+startIndex+"&data_group=ERP_INTERFACE_SWITCH&pageSize="+pageSize+"&"+condition+"&time="+Math.random();
	//alert(url);
	$.getJSON(url, function (data){
		$("#hxqyid").html("");

		//1、表格行内容输出
	    $.each(data.items, function(i,item){
	        var str3 ='';
	        var erpname = "erpSwitch"+item.data_no;
			//str3+= item.data_type_name+':<input type="text" size="2" id=\"'+item.data_no+'\" value=\"'+item.data_name+'"\>';
			str3+=item.data_type_name+':<input type="checkbox" checked id="'+erpname+'" name="'+erpname+'" data-on-text="已开启" data-off-text="已关闭" data-on-color="danger" data-off-color="success" />';
			str3+=' &nbsp;&nbsp;&nbsp;&nbsp;<button type="button"  onclick="javascript:turnOffOrOn(\'true\',\''+item.data_no+'\')" class="btn btn-sm btn-primary" name="editSaveButton" id="editSaveButton">开启</button>';
			str3+=' <button type="button"  onclick="javascript:turnOffOrOn(\'false\',\''+item.data_no+'\')" class="btn btn-sm btn-primary" name="editSaveButton" id="editSaveButton">关闭</button>';
			str3+=' (当前数据库值：'+item.data_name+')说明：已开启=true; 已关闭=false;<br>';
			$("#hxqyid").append(str3);
			$('[type="checkbox"]').bootstrapSwitch(); //没有这句，不会css显示为开关，只是一个checkbox；
			if(item.data_name=="false"){
		    	$('#'+erpname).bootstrapSwitch('toggleState');
		    	$('#'+erpname).bootstrapSwitch('state', false);
		    	$('#'+erpname).bootstrapSwitch('readonly', true);
			}else{
				$('#'+erpname).bootstrapSwitch('toggleState');
				$('#'+erpname).bootstrapSwitch('state', true);
				$('#'+erpname).bootstrapSwitch('readonly', true);
			}
		});//end each data;

    })//end getJSON;
}

//操作后，更新页面上值为新值
function turnOffOrOn(flag, codeno){
	//alert("======flag="+flag+";codeno="+codeno);
	//document.getElementById(codeno).value = flag;
	var url = "<%=basePath%>t_data_dic/updateT_data_dicByDatano?time="+Math.random();
    //var postData = $("#ffAdd").serializeArray();
    var postData = {data_no:codeno,data_name:flag};
    //alert(postData);
   	$.post(url, postData, function (data) {
    	//var data = $.parseJSON(json);
        if (data.result=="success") {
          	showSuccessTips("恭喜修改成功", "提示");
        }
        else {
        	$("#editSaveButton").removeAttr("disabled");
        	showErrorTips("修改数据失败!", "错误信息：");
        }
    }).error(function () {
    	$("#editSaveButton").removeAttr("disabled");
    	showErrorTips("修改数据失败!", "错误信息：");
    });
   	Search1(0);
}

/*
$('#toggle-state-switch').on('switchChange.bootstrapSwitch', function(event, state) {
	  alert("------switchChange this="+this);
	  alert("------switchChange state="+state);
	  //console.log(this); // DOM element
	  //console.log(event); // jQuery event
	  //console.log(state); // true | false
});

$('#toggle-state-switch').on('init.bootstrapSwitch', function(event, state) {
	  alert("------init this="+this);
	  alert("------init state="+state);
	  //$('#toggle-state-switch').bootstrapSwitch('toggleState');
	  //$('#toggle-state-switch').bootstrapSwitch('setState', false); // true || false

	  //alert("------init set default value:false="+this);
	  //$.fn.bootstrapSwitch.defaults.state = true;
	  //$('#toggle-state-switch').bootstrapSwitch('state', true);
	  //$.fn.bootstrapSwitch.defaults.state = "true";
      //$('#toggle-state-switch').bootstrapSwitch('state', true, true); //死循环
      //$('#toggle-state-switch').bootstrapSwitch('setState', false);//死循环
      //$('#toggle-state-switch').bootstrapSwitch('state', true);
	  //alert("------init set default value:true="+state);


});
*/

</script>
